package me.zhengjie.modules.system.rest;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import me.zhengjie.annotation.AnonymousAccess;
import me.zhengjie.annotation.Log;
import me.zhengjie.modules.system.domain.Advert;
import me.zhengjie.modules.system.service.AdvertService;
import me.zhengjie.modules.system.service.IdentityAcctOperateManagerService;
import me.zhengjie.modules.system.service.dto.operate.OperateManagerOrderListReqDTO;
import me.zhengjie.modules.system.service.dto.operate.OperateManagerReqDTO;
import me.zhengjie.modules.system.service.dto.operate.SalesPerformanceReqDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequiredArgsConstructor
@Api(tags = "身份账号运营管理")
@RequestMapping("/api/operateManager")
public class IdentityAcctOperateManagerController {

    @Autowired
    private IdentityAcctOperateManagerService identityAcctOperateManagerService;

    @GetMapping("/salesPerformance")
    @Log("销售业绩")
    @ApiOperation("销售业绩")
    @PreAuthorize("@el.check('operateManager:list')")
    public ResponseEntity<Object> salesPerformance(SalesPerformanceReqDTO criteria){
        return new ResponseEntity<>(identityAcctOperateManagerService.salesPerformance(criteria),HttpStatus.OK);
    }

    @GetMapping("/list")
    @Log("查询运营管理")
    @ApiOperation("查询运营管理")
    @PreAuthorize("@el.check('operateManager:list')")
    public ResponseEntity<Object> query(OperateManagerReqDTO criteria, Pageable pageable){
        return new ResponseEntity<>(identityAcctOperateManagerService.operateManager(criteria,pageable),HttpStatus.OK);
    }

    @GetMapping("orderList")
    @Log("查询运营管理业绩订单明细")
    @ApiOperation("查询运营管理业绩订单明细")
    @PreAuthorize("@el.check('operateManager:list')")
    public ResponseEntity<Object> orderList(OperateManagerOrderListReqDTO criteria, Pageable pageable){
        return new ResponseEntity<>(identityAcctOperateManagerService.orderList(criteria,pageable),HttpStatus.OK);
    }

    @GetMapping("superiorChain")
    @Log("查询运营管理业绩上级链条")
    @ApiOperation("查询运营管理业绩上级链条")
    @PreAuthorize("@el.check('operateManager:list')")
    public ResponseEntity<Object> superiorChain(OperateManagerOrderListReqDTO criteria){
        return new ResponseEntity<>(identityAcctOperateManagerService.superiorChain(criteria.getOpenId()),HttpStatus.OK);
    }

    @GetMapping("/partnerList")
    @Log("城市合伙人列表")
    @ApiOperation("城市合伙人列表")
    @PreAuthorize("@el.check('operateManager:list')")
    public ResponseEntity<Object> partnerList(){
        return new ResponseEntity<>(identityAcctOperateManagerService.partnerList(),HttpStatus.OK);
    }

    @GetMapping("/partnerUserList")
    @Log("城市合伙人成员列表")
    @ApiOperation("城市合伙人成员列表")
    @PreAuthorize("@el.check('operateManager:list')")
    public ResponseEntity<Object> partnerUserList(){
        return new ResponseEntity<>(identityAcctOperateManagerService.partnerUserList(),HttpStatus.OK);
    }

    @GetMapping("/loginUserIdentity")
    @Log("查询登录用户身份")
    @ApiOperation("查询登录用户身份")
    //@PreAuthorize("@el.check('operateManager:list')")
    @AnonymousAccess
    public ResponseEntity<Object> loginUserIdentity(){
        return new ResponseEntity<>(identityAcctOperateManagerService.loginUserIdentity(),HttpStatus.OK);
    }
}